//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "AssetSwap.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/CashFlow.h>
#include <gen/QL/Instruments/Bond.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Times/Schedule.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instruments/Swap.h>
using namespace Cephei::QL;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (Boolean payBondCoupon, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>^ floatSchedule, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<Boolean>^ parAssetSwap, Cephei::QL::IPricingEngine^ QL_Pricer) : CSwap(CAssetSwap::typeid)
{
    CBond^ _Cbond;
    CIborIndex^ _CiborIndex;
    CSchedule^ _CfloatSchedule;
    CDayCounter^ _CfloatingDayCount;
    try
    {
#ifdef HANDLE
        _phAssetSwap = NULL;
#endif
        bool _payBondCoupon = (bool)ValueHelper::Convert (payBondCoupon); //d
        _Cbond = safe_cast<CBond^> (bond);
        _Cbond->Lock();
        boost::shared_ptr<QuantLib::Bond>& _bond = static_cast<boost::shared_ptr<QuantLib::Bond>&> (_Cbond->GetShared ()); 
        QuantLib::Real _bondCleanPrice = (QuantLib::Real)ValueHelper::Convert (bondCleanPrice); //d
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Spread _spread = (QuantLib::Spread)ValueHelper::Convert (spread); //d
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>::IsSome::get (floatSchedule))
        {
            _CfloatSchedule = safe_cast<CSchedule^> (floatSchedule->Value);
            _CfloatSchedule->Lock();
        }
        QuantLib::Schedule& _floatSchedule = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>::IsSome::get (floatSchedule) ? static_cast<QuantLib::Schedule&> (_CfloatSchedule->GetReference ()) : QuantLib::Schedule()); //1
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (floatingDayCount))
        {
            _CfloatingDayCount = safe_cast<CDayCounter^> (floatingDayCount->Value);
            _CfloatingDayCount->Lock();
        }
        QuantLib::DayCounter& _floatingDayCount = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (floatingDayCount) ? static_cast<QuantLib::DayCounter&> (_CfloatingDayCount->GetReference ()) : QuantLib::DayCounter()); //1
        bool _parAssetSwap = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (parAssetSwap) ? (bool)ValueHelper::Convert (parAssetSwap->Value) : true); //4
        _ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (new QuantLib::AssetSwap ( _payBondCoupon,  _bond,  _bondCleanPrice,  _iborIndex,  _spread,  _floatSchedule,  _floatingDayCount,  _parAssetSwap ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppAssetSwap)->setPricingEngine (_QL_Pricer);
        SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cbond != nullptr) _Cbond->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CfloatSchedule != nullptr) _CfloatSchedule->Unlock();
        if (_CfloatingDayCount != nullptr) _CfloatingDayCount->Unlock();
    }
}
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (Boolean parAssetSwap, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Double nonParRepayment, Double gearing, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<DateTime>^ dealMaturity, Microsoft::FSharp::Core::FSharpOption<Boolean>^ payBondCoupon, Cephei::QL::IPricingEngine^ QL_Pricer) : CSwap(CAssetSwap::typeid)
{
    CBond^ _Cbond;
    CIborIndex^ _CiborIndex;
    CDayCounter^ _CfloatingDayCount;
    try
    {
#ifdef HANDLE
        _phAssetSwap = NULL;
#endif
        bool _parAssetSwap = (bool)ValueHelper::Convert (parAssetSwap); //d
        _Cbond = safe_cast<CBond^> (bond);
        _Cbond->Lock();
        boost::shared_ptr<QuantLib::Bond>& _bond = static_cast<boost::shared_ptr<QuantLib::Bond>&> (_Cbond->GetShared ()); 
        QuantLib::Real _bondCleanPrice = (QuantLib::Real)ValueHelper::Convert (bondCleanPrice); //d
        QuantLib::Real _nonParRepayment = (QuantLib::Real)ValueHelper::Convert (nonParRepayment); //d
        QuantLib::Real _gearing = (QuantLib::Real)ValueHelper::Convert (gearing); //d
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Spread _spread = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (spread) ? (QuantLib::Spread)ValueHelper::Convert (spread->Value) : 0.0); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (floatingDayCount))
        {
            _CfloatingDayCount = safe_cast<CDayCounter^> (floatingDayCount->Value);
            _CfloatingDayCount->Lock();
        }
        QuantLib::DayCounter& _floatingDayCount = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (floatingDayCount) ? static_cast<QuantLib::DayCounter&> (_CfloatingDayCount->GetReference ()) : QuantLib::DayCounter()); //1
        QuantLib::Date _dealMaturity = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (dealMaturity) ? (QuantLib::Date)ValueHelper::Convert (dealMaturity->Value) : QuantLib::Date()); //4
        bool _payBondCoupon = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (payBondCoupon) ? (bool)ValueHelper::Convert (payBondCoupon->Value) : false); //4
        _ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (new QuantLib::AssetSwap ( _parAssetSwap,  _bond,  _bondCleanPrice,  _nonParRepayment,  _gearing,  _iborIndex,  _spread,  _floatingDayCount,  _dealMaturity,  _payBondCoupon ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppAssetSwap)->setPricingEngine (_QL_Pricer);
        SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cbond != nullptr) _Cbond->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CfloatingDayCount != nullptr) _CfloatingDayCount->Unlock();
    }
}
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (boost::shared_ptr<QuantLib::AssetSwap>& childNative, Object^ owner) : CSwap(CAssetSwap::typeid)
{
#ifdef HANDLE
	_phAssetSwap = NULL;
#endif
	_ppAssetSwap = &childNative;
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
}
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (QuantLib::AssetSwap& childNative, Object^ owner) : CSwap(CAssetSwap::typeid)
{
#ifdef HANDLE
	_phAssetSwap = NULL;
#endif
	_ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (&childNative);
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
    _AssetSwapOwner = owner;
    _SwapOwner = owner;
}

Cephei::QL::Instruments::CAssetSwap::CAssetSwap (CAssetSwap^ copy) : CSwap(CAssetSwap::typeid)
{
#ifdef HANDLE
	_phAssetSwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (copy->GetShared());
        _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
    }
}
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (PLATFORM::Type^ t) : CSwap(CAssetSwap::typeid)
{
#ifdef HANDLE
	_phAssetSwap = NULL;
#endif
	if (!t->IsSubclassOf(CAssetSwap::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (QuantLib::Handle<QuantLib::AssetSwap>& childNative, Object^ owner)  : CSwap(CAssetSwap::typeid)
{
	_phAssetSwap = &childNative;
	_ppAssetSwap = &static_cast<boost::shared_ptr<QuantLib::AssetSwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
    _AssetSwapOwner = owner;
}
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (QuantLib::Handle<QuantLib::AssetSwap> childNative)  : CSwap(CAssetSwap::typeid)
{
	_phAssetSwap = &childNative;
	_ppAssetSwap = &static_cast<boost::shared_ptr<QuantLib::AssetSwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CAssetSwap::CAssetSwap (QuantLib::AssetSwap childNative)  : CSwap(CAssetSwap::typeid)
{
#ifdef HANDLE
	_phAssetSwap = NULL;
#endif
	_ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (new QuantLib::AssetSwap (childNative));
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
}
#endif

Cephei::QL::Instruments::CAssetSwap::~CAssetSwap ()
{
    if (_ppAssetSwap != NULL)
    {
	    delete _ppAssetSwap;
        _ppAssetSwap = NULL;
    }
}
Cephei::QL::Instruments::CAssetSwap::!CAssetSwap ()
{
    if (_ppAssetSwap != NULL)
    {
	    delete _ppAssetSwap;
    }
}
QuantLib::AssetSwap& Cephei::QL::Instruments::CAssetSwap::GetReference ()
{
    if (_ppAssetSwap == NULL) throw REFNEW NativeNullException ();
	return **_ppAssetSwap;
}
boost::shared_ptr<QuantLib::AssetSwap>& Cephei::QL::Instruments::CAssetSwap::GetShared ()
{
    if (_ppAssetSwap == NULL) throw REFNEW NativeNullException ();
	return *_ppAssetSwap;
}
QuantLib::AssetSwap* Cephei::QL::Instruments::CAssetSwap::GetPointer ()
{
    if (_ppAssetSwap == NULL) throw REFNEW NativeNullException ();
	return &**_ppAssetSwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AssetSwap>& Cephei::QL::Instruments::CAssetSwap::GetHandle ()
{
	if (_phAssetSwap == NULL)
	{
		_phAssetSwap = new Handle<QuantLib::AssetSwap> (*_ppAssetSwap);
	}
	return *_phAssetSwap;
}
#endif
bool Cephei::QL::Instruments::CAssetSwap::HasNative () 
{
	return (_ppAssetSwap != NULL);
}

Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CAssetSwap::BondLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppAssetSwap)->bondLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::FairSpread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppAssetSwap)->fairSpread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CAssetSwap::FloatingLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppAssetSwap)->floatingLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IBond^ Cephei::QL::Instruments::CAssetSwap::Bond::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::Bond>& _rv = (boost::shared_ptr<QuantLib::Bond>&)(*_ppAssetSwap)->bond ( );   
        Cephei::QL::Instruments::CBond^ _nrv = REFNEW Cephei::QL::Instruments::CBond (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::FloatingLegBPS::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->floatingLegBPS ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::Spread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppAssetSwap)->spread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::FairCleanPrice::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->fairCleanPrice ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Instruments::CAssetSwap::ParSwap::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppAssetSwap)->parSwap ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::CleanPrice::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->cleanPrice ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::FairNonParRepayment::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->fairNonParRepayment ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::FloatingLegNPV::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->floatingLegNPV ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CAssetSwap::NonParRepayment::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAssetSwap)->nonParRepayment ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Instruments::CAssetSwap::PayBondCoupon::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppAssetSwap)->payBondCoupon ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IAssetSwap^ Cephei::QL::Instruments::CAssetSwap_Factory::Create (Boolean payBondCoupon, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>^ floatSchedule, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<Boolean>^ parAssetSwap, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CAssetSwap ( payBondCoupon,  bond,  bondCleanPrice,  iborIndex,  spread,  floatSchedule,  floatingDayCount,  parAssetSwap,  QL_Pricer);
}
Cephei::QL::Instruments::IAssetSwap^ Cephei::QL::Instruments::CAssetSwap_Factory::Create (Boolean parAssetSwap, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Double nonParRepayment, Double gearing, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<DateTime>^ dealMaturity, Microsoft::FSharp::Core::FSharpOption<Boolean>^ payBondCoupon, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CAssetSwap ( parAssetSwap,  bond,  bondCleanPrice,  nonParRepayment,  gearing,  iborIndex,  spread,  floatingDayCount,  dealMaturity,  payBondCoupon,  QL_Pricer);
}
